<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace Plugin\Organization\Service;

use Plugin\Organization\Repository\RdOrganizeProjLineRepository;
use Plugin\Organization\Repository\RdOrganizeZoneRepository;
use App\Service\IService;

/**
 * 大区表服务类
 */
final class RdOrganizeZoneService extends IService
{
    public function __construct(
        protected readonly RdOrganizeZoneRepository $repository,
        protected readonly RdOrganizeProjLineService $projLineService,
    ) {}

    public function getAllowedUpdateData($data): array
    {
        return array_flip(['name', 'status', 'sort', 'remark']);
    }

    public function deleteById(mixed $id): int
    {
        // 先删除关联的项目线（以及更深层的关联数据）
        $this->projLineService->deleteByZoneId($id);
        // 再删除大区本身
        return parent::deleteById($id);
    }
}